package network.protocol;
import network.byteConversions.ByteConverter;
import network.dataFormats.GroToGO;
import network.dataFormats.NetworkPackage;
import network.dataFormats.PackageType;
import network.serializing.SerializeBody;
import network.serializing.SerializeGameObject;
import network.serializing.SerializeGraphicsObject;
import network.serializing.SerializeJoint;
import game.objects.GameObject;
import graphics.objects.GraphicsObject;
import physics.Body;
import physics.joints.Joint;
/**
 * Contains methods to create packages that signalize that bodies, joints, graphicsObjects or gameObjects need to be removed in a client.
 * 
 * @author toni
 * 
 */
public class PackageCreator {
	public static NetworkPackage addBodyPackage(Body b, int id, float time) {
		return new NetworkPackage(PackageType.ADDB, SerializeBody.toData(b), id, time);
	}
	public static NetworkPackage remBodyPackage(Body b, int id, float time) {
		return new NetworkPackage(PackageType.REMB, ByteConverter.intToBytes(b.id), id, time);
	}
	public static NetworkPackage addJointPackage(Joint j, int id, float time) {
		return new NetworkPackage(PackageType.ADDJ, SerializeJoint.toData(j), id, time);
	}
	public static NetworkPackage remJointPackage(Joint j, int id, float time) {
		return new NetworkPackage(PackageType.REMJ, ByteConverter.intToBytes(j.id), id, time);
	}
	public static NetworkPackage addGraphicsObjectPackage(GraphicsObject o, int id, float time) {
		return new NetworkPackage(PackageType.ADDG, SerializeGraphicsObject.toData(o), id, time);
	}
	public static NetworkPackage remGraphicsObjectPackage(GraphicsObject o, int id, float time) {
		return new NetworkPackage(PackageType.REMG, ByteConverter.intToBytes(o.id), id, time);
	}
	public static NetworkPackage addGameObjectPackage(GameObject go, int id, float time) {
		return new NetworkPackage(PackageType.ADDGO, SerializeGameObject.toData(go), id, time);
	}
	public static NetworkPackage remGameObjectPackage(GameObject go, int id, float time) {
		return new NetworkPackage(PackageType.REMGO, ByteConverter.intToBytes(go.id), id, time);
	}
	public static NetworkPackage addBodyToGameObjectPackage(int goId, int bId, int id, float time) {
		return new NetworkPackage(PackageType.ADDBTOGO, ByteConverter.twoIntsToBytes(goId, bId), id, time);
	}
	public static NetworkPackage addJointToGameObjectPackage(int goId, int jId, int id, float time) {
		return new NetworkPackage(PackageType.ADDJTOGO, ByteConverter.twoIntsToBytes(goId, jId), id, time);
	}
	public static NetworkPackage addGraphicsObjectToGameObjectPackage(GroToGO g, int id, float time) {
		return new NetworkPackage(PackageType.ADDGROTOGO, ByteConverter.groToGOToData(g), id, time);
	}
	public static NetworkPackage timeSync(int currentFps, int id, float time) {
		long localTime = System.currentTimeMillis();
		byte[] data = new byte[16];
		ByteConverter.floatToFourBytes(time, data, 0);
		ByteConverter.longToEightBytes(localTime, data, 4);
		ByteConverter.intToFourBytes(currentFps, data, 12);
		return new NetworkPackage(PackageType.TIMESYNC, data, id, time);
	}
}
